package com.dlsy.ygj.dao.affair.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import net.taobaoge.common.framework.dao.impl.BaseDAOImpl;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.dlsy.ygj.entity.MerchandiseBatchStocking;

public class MerchandiseBatchStockingDAO extends
		BaseDAOImpl<MerchandiseBatchStocking> {

	@SuppressWarnings("unchecked")
	public List findBatchByCommodityReceivingDepository(final int ID,
			final int strorefrontId) {
		return getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				List StockingAccessList1 = new ArrayList();
				String hql = "SELECT distinct M.batchStockingReceivingDepository From MerchandiseBatchStocking M where M.merchandiseId=? and M.strorefrontId=?";
				Query q = session.createQuery(hql);
				q.setInteger(0, ID);
				q.setInteger(1, strorefrontId);
				List StockingAccessList = q.list();
				if (StockingAccessList.size() > 0) {
					for (Iterator it = StockingAccessList.iterator(); it
							.hasNext();) {
						String batchStockingReceivingDepository = (String) it
								.next();
						StockingAccessList1
								.add(batchStockingReceivingDepository);
					}
				}
				session.clear();
				session.close();
				return StockingAccessList1;
			}
		});
	}

	@SuppressWarnings("unchecked")
	public List findBatchByCommoditybatchStockingPresent(final int ID,
			final int strorefrontId) {
		return getHibernateTemplate().executeFind(new HibernateCallback() {
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				List StockingAccessList1 = new ArrayList();
				String hql = "SELECT distinct M.batchStockingPresent From MerchandiseBatchStocking M where M.merchandiseId=? and M.strorefrontId=?";
				Query q = session.createQuery(hql);
				q.setInteger(0, ID);
				q.setInteger(1, strorefrontId);
				List StockingAccessList = q.list();
				if (StockingAccessList.size() > 0) {
					for (Iterator it = StockingAccessList.iterator(); it
							.hasNext();) {               
						String batchStockingPresent = (String) it.next();
						StockingAccessList1.add(batchStockingPresent);
					}
				}
				session.clear();
				session.close();
				return StockingAccessList1;
			}
		});
	}
}
